package com.youths.controller;

import com.google.gson.Gson;
import com.youths.service.SliceService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.apache.tomcat.jni.Time;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * Created by IntelliJ IDEA.
 * User: KingRainGrey
 * Date: 2020/7/1
 */
@Controller
@RequestMapping(value = "/test/")
@Slf4j
public class SimulationController {
    @Autowired
    SliceService sliceService;


    //模拟dicom转jpg接口
    @PostMapping(value = "savedicom")
    @ResponseBody
    public String dicomToJpg(@RequestParam("file") MultipartFile file) {
        try {
            log.info("save:" + file.getOriginalFilename());
            Time.sleep(1500);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "{\n" +
                "  \"PatientID\": \"JY170110\",\n" +
                "  \"PatientName\": \"吴涵琪\",\n" +
                "  \"PatientBirthDate\": \"20110611\",\n" +
                "  \"PatientSex\": \"F\",\n" +
                "  \"StudyID\": \"1\",\n" +
                "  \"StudyDate\": \"\",\n" +
                "  \"StudyTime\": \"083944.210\",\n" +
                "  \"Error\": 0,\n" +
                "  \"JpgSavePath\": \"D:/dicom/D1E0GDG0/D1E0GDG0.jpg\",\n" +
                "  \"HttpPath\": \"D:/dicom/D1E0GDG0/D1E0GDG0.jpg\",\n" +
                "  \"DicomPath\": \"D:/dicom/D1E0GDG0.dcm\"\n" +
                "}";
    }

    //切割接口
    @GetMapping(value = "slice/{dir}/{path}")
    @ResponseBody
    public String slice() {
        try {
            Time.sleep(5000);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "{\n" +
                "  \"code\": 0,\n" +
                "  \"data\": \"../rcnn-results/test/丁瑜鑫\"\n" +
                "}";
    }

    //模型识别接口
    @GetMapping(value = "recoImg",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String recoImg(@RequestParam("image_path") String imagePath,
                          @RequestParam("sex") Boolean sex,//0男  1女
                          @RequestParam("age") Double age) {
        try {
            Time.sleep(10000);
        }catch (Exception e) {

        }
        log.info("image_path:" + imagePath + "sex:" + sex + "age:" + age);
        return "{\n" +
                "  \"code\": \"success\",\n" +
                "  \"message\": \"识别成功\",\n" +
                "  \"data\": {\n" +
                "    \"gou\": 8,\n" +
                "    \"jin1\": 7,\n" +
                "    \"jin3\": 7,\n" +
                "    \"jin5\": 7,\n" +
                "    \"rao\": 7,\n" +
                "    \"tou\": 7,\n" +
                "    \"yuan1\": 8,\n" +
                "    \"yuan3\": 8,\n" +
                "    \"yuan5\": 8,\n" +
                "    \"zhang1\": 7,\n" +
                "    \"zhang3\": 7,\n" +
                "    \"zhang5\": 6,\n" +
                "    \"zhong3\": 6,\n" +
                "    \"zhong5\": 8,\n" +
                "    \"chi\": 6,\n" +
                "    \"chn_boneage\": 15.4,\n" +
                "    \"tw3_boneage\": 15.0,\n" +
                "    \"twc_boneage\": 16.0,\n" +
                "    \"situation\": \"您的孩子发育情况属于正常发育:生活年龄为16.0岁，CHN骨龄为15.4岁，差距为0.6岁。\"\n" +
                "  }\n" +
                "}";
    }

    @GetMapping(value = "count",produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String count(@RequestParam("rao") Integer rao,
                        @RequestParam("gou") Integer gou,
                        @RequestParam("tou") Integer tou,
                        @RequestParam("zhang1") Integer zhang1,
                        @RequestParam("zhang3") Integer zhang3,
                        @RequestParam("zhang5") Integer zhang5,
                        @RequestParam("jin1") Integer jin1,
                        @RequestParam("jin3") Integer jin3,
                        @RequestParam("jin5") Integer jin5,
                        @RequestParam("zhong3") Integer zhong3,
                        @RequestParam("zhong5") Integer zhong5,
                        @RequestParam("yuan1") Integer yuan1,
                        @RequestParam("yuan3") Integer yuan3,
                        @RequestParam("yuan5") Integer yuan5,
                        @RequestParam("chi") Integer chi,
                        @RequestParam("age") Double age) {

        Double chn = Math.random() + 15.0;
        Double tw3 = Math.random() + 14.0;
        Double twc = Math.random() + 16.0;

        return "{\n" +
                "  \"code\": \"success\",\n" +
                "  \"message\": \"计算完成\",\n" +
                "  \"data\": {\n" +
                "    \"chn_boneage\": " + chn + ",\n" +
                "    \"tw3_boneage\": " + tw3 + ",\n" +
                "    \"twc_boneage\": " + twc + ",\n" +
                "    \"situation\": \"您的孩子发育情况属于正常发育:生活年龄为16.0岁，CHN骨龄为15.3岁，差距为0.7岁。\"\n" +
                "  }\n" +
                "}";
    }

    //模拟身高接口
    //mock:https://9395fa35-4718-474a-aaf6-500a734914c2.mock.pstmn.io/heightplot
    @GetMapping(value = "heightplot", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String heightPlot(@Param("age") Float age, //带一位小数 计算方法？
                              @Param("boneage") Float boneage,
                              @Param("sex") String sex,
                              @Param("height") Float height,
                              @Param("yichuanx") Float yichuanx, //父母身高？
                              @Param("yichuany") Float yichuany) {

//        try {
//            log.info("heightplot:" + age + " " + boneage + " " + sex + " " + height + " " + yichuanx + " " + yichuany);
//            Time.sleep(1000);
//        }catch (Exception e) {
//            e.printStackTrace();
//        }
        return "{\n" +
                "  \"bp\": 175.6,\n" +
                "  \"bp2\": 177.2,\n" +
                "  \"forecast\": [\n" +
                "    [\n" +
                "      11.3,\n" +
                "      145.7\n" +
                "    ],\n" +
                "    [\n" +
                "      11.5,\n" +
                "      146.98320030793118\n" +
                "    ],\n" +
                "    [\n" +
                "      12.0,\n" +
                "      150.1801606415528\n" +
                "    ],\n" +
                "    [\n" +
                "      12.5,\n" +
                "      153.04894735134374\n" +
                "    ],\n" +
                "    [\n" +
                "      13.0,\n" +
                "      154.84318438937743\n" +
                "    ],\n" +
                "    [\n" +
                "      13.5,\n" +
                "      156.04981671076195\n" +
                "    ],\n" +
                "    [\n" +
                "      14.0,\n" +
                "      157.08908249621018\n" +
                "    ],\n" +
                "    [\n" +
                "      14.5,\n" +
                "      158.3719729121503\n" +
                "    ],\n" +
                "    [\n" +
                "      15.0,\n" +
                "      159.416433939128\n" +
                "    ],\n" +
                "    [\n" +
                "      15.5,\n" +
                "      160.46499431061224\n" +
                "    ],\n" +
                "    [\n" +
                "      16.0,\n" +
                "      160.96912567686783\n" +
                "    ],\n" +
                "    [\n" +
                "      16.5,\n" +
                "      161.30584470884727\n" +
                "    ],\n" +
                "    [\n" +
                "      17.0,\n" +
                "      161.5461992431872\n" +
                "    ],\n" +
                "    [\n" +
                "      17.5,\n" +
                "      161.7413320906068\n" +
                "    ],\n" +
                "    [\n" +
                "      18.0,\n" +
                "      161.9309584639341\n" +
                "    ]\n" +
                "  ],\n" +
                "  \"message\": \"现身高<span class='anal'>145.7</span>cm,处于同龄青少年身高<span class='anal'>[1] \\\"0SD ~ +1SD\\\"</span>范围。<br>父亲身高<span class='anal'>165</span>cm，母亲身高<span class='anal'>174</span>cm，孩子的遗传靶身高<span class='anal'>163.0</span>cm。<br>CHN-BP预测成年后身高<span class='anal'>175.6</span><span class='anal'>±3.0</span>cm。<br>改进BP预测成年后身高<span class='anal'>177.2</span><span class='anal'>±2.0</span>cm。<br>预测身高<span class='anal' style='color:orangered'>高于</span>遗传靶身高（期望值），成年后<span class='anal' style='color:orangered'>高于</span>女性平均身高172.7cm。<br>\",\n" +
                "  \"target\": 163.0\n" +
                "}";
    }

    @GetMapping(value = "heightplot2", produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public String heightplot2() {
        return "{\n" +
                "  \"bp\": 175.6,\n" +
                "  \"bp2\": 177.2,\n" +
                "  \"forecast\": [\n" +
                "    [\n" +
                "      11.3,\n" +
                "      145.7\n" +
                "    ],\n" +
                "    [\n" +
                "      11.5,\n" +
                "      146.98320030793118\n" +
                "    ],\n" +
                "    [\n" +
                "      12.0,\n" +
                "      150.1801606415528\n" +
                "    ],\n" +
                "    [\n" +
                "      12.5,\n" +
                "      153.04894735134374\n" +
                "    ],\n" +
                "    [\n" +
                "      13.0,\n" +
                "      154.84318438937743\n" +
                "    ],\n" +
                "    [\n" +
                "      13.5,\n" +
                "      156.04981671076195\n" +
                "    ],\n" +
                "    [\n" +
                "      14.0,\n" +
                "      157.08908249621018\n" +
                "    ],\n" +
                "    [\n" +
                "      14.5,\n" +
                "      158.3719729121503\n" +
                "    ],\n" +
                "    [\n" +
                "      15.0,\n" +
                "      159.416433939128\n" +
                "    ],\n" +
                "    [\n" +
                "      15.5,\n" +
                "      160.46499431061224\n" +
                "    ],\n" +
                "    [\n" +
                "      16.0,\n" +
                "      160.96912567686783\n" +
                "    ],\n" +
                "    [\n" +
                "      16.5,\n" +
                "      161.30584470884727\n" +
                "    ],\n" +
                "    [\n" +
                "      17.0,\n" +
                "      161.5461992431872\n" +
                "    ],\n" +
                "    [\n" +
                "      17.5,\n" +
                "      161.7413320906068\n" +
                "    ],\n" +
                "    [\n" +
                "      18.0,\n" +
                "      161.9309584639341\n" +
                "    ]\n" +
                "  ],\n" +
                "  \"message\": \"现身高<span class='anal'>145.7</span>cm,处于同龄青少年身高<span class='anal'>[1] \\\"0SD ~ +1SD\\\"</span>范围。<br>父亲身高<span class='anal'>165</span>cm，母亲身高<span class='anal'>174</span>cm，孩子的遗传靶身高<span class='anal'>163.0</span>cm。<br>CHN-BP预测成年后身高<span class='anal'>175.6</span><span class='anal'>±3.0</span>cm。<br>改进BP预测成年后身高<span class='anal'>177.2</span><span class='anal'>±2.0</span>cm。<br>预测身高<span class='anal' style='color:orangered'>高于</span>遗传靶身高（期望值），成年后<span class='anal' style='color:orangered'>高于</span>女性平均身高172.7cm。<br>\",\n" +
                "  \"target\": 163.0\n" +
                "}";
    }
}
